package org.alps.pattern.strategy.promotion;

import org.apache.commons.lang3.StringUtils;

/**
 * @date 2021-05-01
 * @author zkw
 */
public class PromotionActivityTest {

    public static void main(String[] args) {

        String promotionKey = "GROUPBUY";

        //有新的促销活动，只需要添加新的优惠策略类，并在工厂中添加新的策略，不影响其它已有活动
        PromotionActivity activity = new PromotionActivity(PromotionStrategyFactory.getPromotionStrategy(promotionKey));
        activity.execute();
    }

    //public static void main(String[] args) {

        /**
         * 以下代码需要优化：
         * 促销活动频繁改动，代码也要频繁改动...
         */
        /*PromotionActivity promotionActivity = null;
        String promotionKey = "COUPON";
        if (StringUtils.equalsIgnoreCase(promotionKey, "COUPON")) {
            promotionActivity = new PromotionActivity(new CouponStrategy());
        } else if (StringUtils.equalsIgnoreCase(promotionKey, "CASHBACK")) {
            promotionActivity = new PromotionActivity(new CashbackStrategy());
        } //...

        promotionActivity.execute();*/

        //代码通常不会这么写
        //PromotionActivity activity618 = new PromotionActivity(new CouponStrategy());
        //activity618.execute();
        //
        //PromotionActivity activity1111 = new PromotionActivity(new CashbackStrategy());
        //activity1111.execute();

    //}

}
